home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7682 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  58 lines

  1. Path: titan.fullerton.edu!grosin
  2. From: grosin@titan.fullerton.edu (Gil Rosin)
  3. Newsgroups: comp.lang.c++
  4. Subject: What is referencing good for?
  5. Date: 25 Feb 1996 04:29:33 GMT
  6. Organization: California State University at Fullerton
  7. Message-ID: <4goojd$a9g@wintermute.ecs.fullerton.edu>
  8. NNTP-Posting-Host: titan.ecs.fullerton.edu
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11. I've been playing with referencing all day, and I can not find one use for it
  12. that I can not do with pointers. What is referencing good for? I know about
  13. reference parameters and I know about reference functions.
  14.  
  15. The only pro I found about reference parameters is that it gives cleaner code,
  16. ie, with pointers you get:
  17.  
  18. main()
  19.  {
  20.   int a;
  21.   T(&a);
  22.  }
  23.  
  24. T(int *a)
  25.  {
  26.   *a = 6;
  27.  }
  28.  
  29. while with referencing you get:
  30.  
  31. main()
  32.  {
  33.   int a;
  34.   T(a);
  35.  }
  36.  
  37. T(int &a)
  38.  {
  39.   a = 6;
  40.  }
  41.  
  42. Aside from that, I found referencing to have the same uses as pointers, if I
  43. need to pass huge objects I can pass the address instead of the entire data,
  44. but I can do this with pointers as well.
  45.  
  46. I don't quite understand what reference functions are good for. Again, I can
  47. do the same stuff with pointers.
  48.  
  49. Can someone give me a REAL world example of where I would use referencing
  50. perhaps somewhere that I can not use pointers? 
  51.  
  52. And keep in mind that I'm a newbie, I'm just trying to learn the basics
  53. right now.
  54.  
  55. Thanks, please reply via email to grosin@titan.fullerton.edu
  56.  
  57.  
  58.